home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / bipl.zip / PROCS.ZIP / SLSHUPTO.ICN < prev    next >
Text File  |  1992-12-30  |  2KB  |  67 lines

  1. ############################################################################
  2. #
  3. #    File:     slashupto.icn
  4. #
  5. #    Subject:  Procedure for upto scanning with backslash escaping
  6. #
  7. #    Author:   Richard L. Goerwitz
  8. #
  9. #    Date:     April 10, 1992
  10. #
  11. ###########################################################################
  12. #
  13. #    Version:  1.1
  14. #
  15. ###########################################################################
  16. #
  17. #  Slashupto works just like upto, except that it ignores backslash
  18. #  escaped characters.  I can't even begin to express how often I've
  19. #  run into problems applying Icon's string scanning facilities to
  20. #  to input that uses backslash escaping.  Normally, I tokenize first,
  21. #  and then work with lists.  With slashupto() I can now postpone or
  22. #  even eliminate the traditional tokenizing step, and let Icon's
  23. #  string scanning facilities to more of the work.
  24. #
  25. #  If you're confused:
  26. #
  27. #  Typically UNIX utilities (and probably others) use backslashes to
  28. #  "escape" (i.e. remove the special meaning of) metacharacters.  For
  29. #  instance, UNIX shells normally accept "*" as a shorthand for "any
  30. #  series of zero or more characters.  You can make the "*" a literal
  31. #  "*," with no special meaning, by prepending a backslash.  The rou-
  32. #  tine slashupto() understands these backslashing conventions.  You
  33. #  can use it to find the "*" and other special characters because it
  34. #  will ignore "escaped" characters.
  35. #
  36. ############################################################################
  37. #
  38. #  See also: slashbal.icn
  39. #
  40. ############################################################################
  41.  
  42. #
  43. # slashupto:  cset x string x integer x integer -> integers
  44. #             (c, s, i, j) -> Is (a generator)
  45. #    where Is are the integer positions in s[i:j] before characters
  46. #    in c that is not preceded by a backslash escape
  47. #
  48. procedure slashupto(c, s, i, j)
  49.  
  50.     if /s := &subject
  51.     then /i := &pos
  52.     else /i := 1
  53.     /j := *s + 1
  54.     
  55.     /c := &cset
  56.     c ++:= '\\'
  57.     s[1:j] ? {
  58.         tab(i)
  59.         while tab(upto(c)) do {
  60.             if (="\\", move(1)) then next
  61.             suspend .&pos
  62.             move(1)
  63.         }
  64.     }
  65.  
  66. end
  67.